﻿@using Topro.Entity.Enum;
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="easyui-layout case" data-options="fit: true">
    <div data-options="region: 'center', border: false" style="padding:10px; overflow: hidden;">
        <div class="easyui-layout" data-options="fit: true">
            <div class="easyui-layout" data-options="fit: true">
                <!--header-->
                <div data-options="region:'north',border: false,split:true" style="height:40px;">
                    <div class="data-tools clearfix">
                        <form class="form-inline" id="formSearch" method="get" action="/report/exportExcel">
                        <div class="pull-left form-inline ">
                            <a class="btn btn-default btn-sm add" data-title="导出" onclick="return exportExcel();"><span class="glyphicon glyphicon-plus"></span> 导出</a>
                        </div>
                        <div class="pull-right">
                                <div class="input-group input-group-sm">
                                    <label class="input-group-addon m5_l">开始日期：</label>
                                    <input class="form-control wd90" name="StartTime" type="text" value="@(ViewBag.StartTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" autocomplete="off" />
                                </div>
                                <div class="input-group input-group-sm">
                                    <label class="input-group-addon m5_l">结束日期：</label>
                                    <input class="form-control wd90" name="EndTime" type="text" value="@(ViewBag.EndTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" autocomplete="off" />
                                </div>
                                <div class="input-group input-group-sm">
                                    <label class="input-group-addon m5_l">单据类型：</label>
                                    <select class="form-control wd80" name="orderType">
                                        <option value="">请选择</option>
                                        <option value="10">入库</option>
                                        <option value="20">出库</option>
                                        <option value="30">盘点出库</option>
                                    </select>
                                </div>
                                <div class="input-group input-group-sm">
                                    <label class="input-group-addon m5_l">料号：</label>
                                    <input class="form-control wd100" name="partNo" type="text" autocomplete="off">
                                </div>
                                <div class="input-group input-group-sm">
                                    <label class="input-group-addon m5_l">批号：</label>
                                    <input class="form-control wd100" name="lotNo" type="text" autocomplete="off">
                                </div>
                                <button type="button" class="btn btn-default btn-sm active search" id="btnSearch"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                        </div>
                        </form>
                    </div>
                </div>
                <div data-options="region:'center',split: false, border: false">
                    <!-- 表格数据 -->
                    <table id="stockInDG"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    var stockInDG = $('#stockInDG');

    function Tip_success(word) {
        Topro.UI.Tip_success(word);
    }

    function exportExcel() {
        $("#formSearch").submit();
    }

    $(function () {
        //搜索
        $(".search").click(function(){
            In.search();
        });

        In.doSearch();
    });

    var In = {
        view: function (obj) {
            Topro.UI.DialogOpen($(obj).data("href") + '?v=' + Math.random().toString(36).substr(2, 4), {
                title: $(obj).data("title"),
                width: $(obj).data("width"),
                height: $(obj).data("height")
            });
        },
        search: function () {
            //表单
            var searchform = $("#formSearch").serializeArray();
            //表单转为Json
            var queryParams = In.getJson(searchform);

            stockInDG.datagrid({
                queryParams: queryParams
            });

            return false;
        },
        getJson: function (array) {
            if (array != undefined && array.length > 0) {
                var json = {};
                $(array).each(function (i, v) {
                    json[v.name] = v.value;
                });
                return json;
            } else {
                return {};
            }
        },
        queryParams:function(){
            var params = {
            };

            return params;
        },
        selectProduct: function () {
            Topro.DAO.Product({
                title: '物料',
                isSingle: true,
                saveCallBack: function(rows) {

                    if(rows.length<=0){
                        window.top.$.messager.alert('提示', '请选择物料！', 'info');
                        return;
                    }else{
                        $.each(rows, function(i, item){
                            datagrid.datagrid('insertRow',{
	                            index: 0,
	                            row: item
                            })
                        });
                    }
                }
            });
        },
        doSearch: function () {
            //固定行
            var frozenColumns = [
                [
                    {
                        field: 'resourceId',
                        title: '单据号',
                        width: 150,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return "{0}".format(row.resourceId);
                        }
                    },
                    {
                        field: 'sourceId',
                        title: '来源单据号',
                        width: 150,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return "{0}".format(value);
                        }
                    }
                ]
            ];
            //固定行
            var columns = [
                [
                    {
                        field: 'warehouseUnitTostring',
                        title: '库位 ',
                        width: 120,
                        align: 'left',
                        formatter: function (value, row, index) {

                            var result = "";

                            if (!Topro.Util.isNullOrEmptySpance(value)) {
                                result = value;
                            }

                            return result;
                        }
                    },
                    {
                        field: 'orderType',
                        title: '订单类型 ',
                        width: 75,
                        align: 'center',
                        formatter: function (value, row, index) {
                            if (value == @(InventoryType.入库.GetHashCode())) {
                                return "入库";
                            } else if (value == @(InventoryType.出库.GetHashCode())) {
                                return "出库";
                            } else {
                                return "";
                            }
                        }
                    },
                    {
                        field: 'partNo',
                        title: '料号',
                        width: 220,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return "<span>{0}</span>".format(value);
                        }
                    },
                    {
                        field: 'productName',
                        title: '物料名称',
                        width: 170,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return "<span>{0}</span>".format(value);
                        }
                    },
                    {
                        field: 'qty',
                        title: '数量',
                        width: 75,
                        align: 'right',
                        formatter: function (value, row, index) {
                            if (row.isContainer == @((int)IsContainer.空)) {
                                result = "";
                            } else {
                                return "<span class='red bold'>{0}</span>".format(value);
                            }
                        }
                    },
                    {
                        field: 'lotNo',
                        title: '批号',
                        width: 150,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return "<span>{0}</span>".format(value);
                        }
                    },
                    {
                        field: 'grade',
                        title: '等级',
                        width: 75,
                        align: 'center',
                        formatter: function (value, row, index) {
                            return "<span>{0}</span>".format(value);
                        }
                    },
                    {
                        field: 'containerCode',
                        title: '托盘',
                        width: 70,
                        align: 'left',
                        formatter: function (value, row, index) {
                            var result = "<span>{0}</span>".format(value);

                            if (row.id != -1) {
                                if (row.isContainer == @(IsContainer.空.GetHashCode())) {
                                    result += "<span class='red bold'>(空)</span>"
                                }
                                return result;
                            }
                        }
                    },
                    {
                        field: 'remark',
                        title: '备注',
                        align: 'left',
                        width: 200
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        align: 'center',
                        width: 140,
                        formatter: function (value, row, index) {
                            if (row.id != -1) {
                                return value.replace("T", " ");
                            }
                        }
                    }
                ]
            ];

            Topro.UI.DataGrid(stockInDG, {
                fit: true,
                method: "post",
                url: "@Url.Action("InventoryQuery", "Report")",
                queryParams: In.queryParams(),
                idField: 'id',
                pagination: true,
                pageList : [10,50,100,500,1000,5000],
                singleSelect: true,
                rownumbers: true,
                showFooter: true,
                autoEditing:true,
                frozenColumns: frozenColumns,
                columns: columns
            });
        }
    }
</script>
